var componentGridAddressBasePath = componentAddressBasePath+"/dhtmlxGrid_pro";
var themeGridAddressBasePath = componentGridAddressBasePath;

if(themeAddr != '1') themeGridAddressBasePath = 'theme/'+themeAddr+'/dhtmlx-style';
document.write('<link rel="stylesheet" type="text/css" href="'+themeGridAddressBasePath+'/dhtmlxgrid.css">');
document.write('<link rel="stylesheet" type="text/css" href="'+themeGridAddressBasePath+'/skins/dhtmlxgrid_dhx_'+getThemeAddrSuffix()+'.css">');
document.write('<script src="'+componentAddressBasePath+'/dhtmlxcommon.js"></script>');
document.write('<script src="'+componentGridAddressBasePath+'/dhtmlxgrid.js"></script>');
document.write('<script src="'+componentGridAddressBasePath+'/dhtmlxgridcell.js"></script>');	

function setSkin(grid,skin){
	grid.setSkin(skin || ("dhx_"+ getThemeAddrSuffix() ));
}

function setGridImagePath(grid,imagePath){
	grid.setImagePath(imagePath || (themeGridAddressBasePath+"/imgs/"));
}

function createGridNormal(divid){
	var grid = new dhtmlXGridObject(divid);
	setGridImagePath(grid);
    return grid;
}

function createGridFromTabbar(tabbar,cell){
	var grid = tabbar.cells(cell).attachGrid();
	setGridImagePath(grid);
    return grid;
}
function createGridFromLayout(layout,cell){
    return createGridFromLayoutCell(layout.cells(cell));
}
function createGridFromLayoutCell(cell){
	var grid = cell.attachGrid();
	setGridImagePath(grid);
	//这个页面已经加载完成，关闭等待
	itemProgressOff(cell);
	//判断是否加载数据，如果加载数据打开等待
	layoutCellProgressOn(cell,grid);
	//加载数据后，最后关闭等待
	layoutCellProgressOff(cell,grid);
    return grid;
}
function layoutCellProgressOn(cell,grid){
	grid.attachEvent("onXLS", function(grid_obj,count){itemProgressOn(cell);}); 
}
function layoutCellProgressOff(cell,grid){
	grid.attachEvent("onXLE", function(grid_obj,count){itemProgressOff(cell);}); 
}

function filterBy(mygridParam,inputName) {
	var filterInputName = inputName?inputName:"gridFilter";
	var filters =$('[name="'+filterInputName+'"]'); // var filters =document.getElementsByName(inputName?inputName:"gridFilter");
	var filterArray = new Array();
	for(var i = 0;i<filters.length;i++){
		var v = filters[i].value.toLowerCase();
		var indexId = filters[i].id.split("_")[1];
		filterArray[i] = {indexId:indexId,value:v};
	}
	if(filterArray.length<=0)return;
	for (var i = 0; i < mygridParam.getRowsNum(); i++) {
		var display = true;
		for(var j = 0;j<filterArray.length;j++){
			var indexId = filterArray[j].indexId;
			var value = filterArray[j].value;
			var tStr = mygridParam.cells2(i, indexId).getValue().toString().toLowerCase();
			if(display)
				display = (value == "" || tStr.indexOf(value) >= 0);
			else
				break;
		}
	    mygridParam.setRowHidden(mygridParam.getRowId(i), !display );
	    
	}
}
function populateSelectCell(selObjId,mygridParam,initText) {
	document.getElementById(selObjId).options.length = 0;
    document.getElementById(selObjId).options.add(new Option(initText?initText:"所有内容", ""));
    var usedAuthAr = new dhtmlxArray();
    for (var i = 0; i < mygridParam.getRowsNum(); i++) {
        var authNm = mygridParam.cells2(i, selObjId.split("_")[1]).getValue();
        if (usedAuthAr._dhx_find(authNm) == -1) {
        	document.getElementById(selObjId).options.add(new Option(authNm, authNm));
            usedAuthAr[usedAuthAr.length] = authNm;
        }
    }
}
